package com.surelution.projects.crm

import org.codehaus.groovy.grails.commons.ConfigurationHolder;

class OverviewController {
	
	def exportService
    def springSecurityService
    def index = {
		def location
		if (springSecurityService.isLoggedIn() && springSecurityService.principal.username != 'admin'){
			OwnStation station = User.findByUsername(springSecurityService.principal.username).station
			location = station.longitude + ',' +station.latitude
		} else{
			location = '120.741578,30.748013'
		}
		[latLng:location]
	}
	
	def exportExcel = {
		response.contentType = ConfigurationHolder.config.grails.mime.types['excel']
		response.setHeader("Content-disposition", "attachment; filename=station.xls")
		
		def fields = ["address","latitude","longitude","manager","managerTel","name"]
		def labels = ["address":"地址","latitude":"经度","longitude":"纬度","manager":"manager","managerTel":"managerTel","name":"站名"]

		exportService.export("excel", response.outputStream, OwnStation.list(), fields, labels,[:],[:])
	}
	
	def showLocationPicker = {

		
	}

	def select = {
		String c = params.useSelect
		def lng = params.lng
		def lat = params.lat
		def type = params.type
		def zoom = params.zoom
		if (c=='1'){ 	redirect(controller:"ownStation", action:"create", params:[lat:lat, lng:lng, mapType:type, zoom:zoom])	}
		if (c=='2'){	redirect(controller:"competitorStation", action:"create", params:[lat:lat, lng:lng, mapType:type, zoom:zoom])	}
		if (c=='3'){	redirect(controller:"market", action:"create", params:[lat:lat, lng:lng, mapType:type, zoom:zoom])	}
		if (c=='4'){	redirect(controller:"ownStation", action:"reset", params:[lat:lat, lng:lng, mapType:type, zoom:zoom])	}
		if (c=='5'){	redirect(controller:"competitorStation", action:"reset", params:[lat:lat, lng:lng, mapType:type, zoom:zoom])	}
		if (c=='6'){	redirect(controller:"market", action:"reset", params:[lat:lat, lng:lng, mapType:type, zoom:zoom])	}
		
	}
}
